using System.Globalization;
using FiddlerAmfParser.Rendering;
using FluorineFx.IO;

namespace FiddlerAmfParser.OutputProcessing
{
	internal class DefaultOutputProcessor : IOutputProcessorPlugin
	{
		public byte RenderOrder { get { return 128; } }

		public void ProcessAmfMessage(ParserContext ctx, AMFMessage messageData)
		{
			ctx.Output.TreeView.Nodes.Add("Version", "Version: " + messageData.Version.ToString(CultureInfo.InvariantCulture));
		}

		public void ProcessAmfBody(ParserContext ctx, AMFBody bodyData)
		{
			ctx.Output.TreeView.Nodes.Add("Call", "Call: " + bodyData.Call);
			ctx.Output.TreeView.Nodes.Add("Target", "Target: " + bodyData.Target);
			ctx.Output.TreeView.Nodes.Add("Method", "Method: " + bodyData.Method);
			ctx.Output.TreeView.Nodes.Add("TypeName", "TypeName: " + bodyData.TypeName);
			ctx.Output.TreeView.Nodes.Add("Response", "Response: " + bodyData.Response);

			var contentNode = ctx.Output.TreeView.Nodes.Add("Content", "Content");
			
			AmfRenderer.RenderValue(bodyData.Content, contentNode);
		}
	}
}